package com.example.xm.service.impl;

import com.example.xm.entity.Huiyuan;
import com.example.xm.entity.Tiaozhan;
import com.example.xm.entity.Timu;
import com.example.xm.entity.Udaan;
import com.example.xm.exception.SerceiceException;
import com.example.xm.mapper.HuiyuanMapper;
import com.example.xm.mapper.TiaozhanMapper;
import com.example.xm.mapper.TimuMapper;
import com.example.xm.mapper.UdaanMapper;
import com.example.xm.service.IHuiyuanService;
import com.example.xm.service.ITiaozhanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TiaozhanService implements ITiaozhanService {
    @Autowired
    TiaozhanMapper shipinfenleiMapper;
    @Autowired
    TimuMapper timuMapper;
    @Autowired
    UdaanMapper udaanMapper;
    @Override
    public void reg(Tiaozhan fenlei) {
        fenlei.setTime(new Date());
        shipinfenleiMapper.insert(fenlei);
      List<Timu> list=  timuMapper.rand();
        for (Timu timu : list) {
            Udaan udaan = new Udaan();
            udaan.setTid(timu.getId());
            udaan.setDaan(timu.getDaan());
            udaan.setUid(Long.valueOf(fenlei.getUid()));
            udaan.setTiaozhanid(fenlei.getId());
            udaanMapper.insertUdaan(udaan);
        }
    }

    @Override
    public List<Tiaozhan> list(Integer uid) {
        List<Tiaozhan> adminList=  shipinfenleiMapper.selectList(uid);
        return adminList;
    }
}
